{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% import "demand/partial/search_demand_form.html" as search_demand_form_macro %}
{% import "demand/partial/demand_table.html" as demand_table_macro %}

{% block title %}万屏时代OPC--{{page_title}}{% endblock %}

{% block panel_heading %}
  万屏时代OPC--{{page_title}}
  <div class="pull-right btn-group">
    <a href="{{ url_for('op_bp.add_demand') }}" class="btn btn-sm btn-success" target="_blank">
        新建项目
    </a>
  </div>
{% endblock %}

{% block panel_body %}
    {{ search_demand_form_macro.gen_form(form, form_route, can_export, current_user) }}

    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, url, **url_kwargs) }}
    </div>
    {% endif %}

    {{ demand_table_macro.gen_table(demands) }}

    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, url, **url_kwargs) }}
    </div>
    {% endif %}

    <div class="modal fade" id="remark_modal" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title">客户: <span id="remark_modal_client_name"></span>(备注信息)</h4>
              </div>
              <div class="modal-body">
                  <form action="" class="form form-inline">
                      <div class="form-group">
                          <div class="row">
                              <label class="control-label  col-xs-3 col-xs-offset-1" for="reason">管理员备注:</label>
                              <div class="col-xs-8">
                                  <textarea id="remark_modal_admin_remark" rows="10" cols="50" readonly></textarea>
                              </div>
                          </div>
                          <div class="row">
                              <label class="control-label  col-xs-3 col-xs-offset-1" for="reason">客户备注:</label>
                              <div class="col-xs-8">
                                  <textarea id="remark_modal_remark" rows="5" cols="50" readonly></textarea>
                              </div>
                          </div>
                      </div>
                  </form>
              </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block scripts %}
{{ super() }}
    <script>
        $(document).ready(function(){
            $('.show_remark_modal').click(function () {
                $('#remark_modal_client_name').html($(this).data('nickname'));
                $('#remark_modal_admin_remark').val($(this).data('admin-remark'));
                $('#remark_modal_remark').val($(this).data('remark'));
                $('#remark_modal').modal()
            });
            $("#export-demands").click(function () {
                var url = '{{ url_for('op_bp.export_demand_list') }}';
                url = url + '?' +
                    'user_phone=' + $('#user_phone').val() +
                    '&id=' + $('#id').val() +
                    '&uid=' + $('#uid').val() +
                    '&prov=' + $('#prov').val() +
                    '&cate=' + $('#cate').val() +
                    '&malf=' + $('#malf').val() +
                    '&type=' + $('#type').val() +
                    '&surr=' + $('#surr').val() +
                    '&color=' + $('#color').val() +
                    '&status=' + $('#status').val() +
                    '&tag=' + $('#tag').val() +
                    '&source=' + $('#source').val() +
                    '&admin_id=' + $('#admin_id').val() +
                    '&robot_win=' + $('#robot_win').val() +
                    '&created_at_begin=' + $('#created_at_begin').val() +
                    '&created_at_end=' + $('#created_at_end').val() +
                    '&published_at_begin=' + $('#published_at_begin').val() +
                    '&published_at_end=' + $('#published_at_end').val() +
                    '&is_for_gold=' + $('#is_for_gold').val() +
                    '&remark=' + $('#remark').val() +
                    '&admin_remark=' + $('#admin_remark').val();
                if ($('#has_audio').is(':checked')) {
                    url = url + '&has_audio=1'
                }
                if ($('#ignore_invalid').is(':checked')) {
                    url = url + '&ignore_invalid=1'
                }
                window.location.href = url;
            });
        })
    </script>
{% endblock %}
